/**
 * 采购合同管理
 */
app.controller('btnCtrl', ['$scope', '$http', BtnController]);
function BtnController($scope, $http){
    console.log('------$scope.menuId1-----', $scope.menuId);
    console.log('------$scope.buttonArr1-----', $scope.buttonArr);

    $scope.bindBtn = function(event) {
        var datas = $scope.getSelectedRows();
        switch(event){
            case 'event-to-cancel': {//采购取消
                if(datas.length == 0) {
                    layer.alert('尚未选中数据');
                } else if(datas.length > 1) {
                    layer.alert('只能选中一行数据');
                } else {
                    var subPaymentNum = datas[0].subPaymentNum;
                    var subWarehousingNum = datas[0].subWarehousingNum;
                    var subWriteOffNum = datas[0].subWriteOffNum;
                    if(subPaymentNum != 0 ||  subWarehousingNum!=0 || subWriteOffNum!=0){
                        return layer.msg("子件存在付款数量、入库数量、核销数量不允许取消");
                    }
                    layer.confirm('确定要取消吗？', { icon: 3 }, function() {
                        layer.msg('处理中', { icon: 16, shade: 0.01 });

                        $http.post('/api/inter/tcgPurchaseContractByManage/cancelInfo', {}, {params: {itemId: datas[0].itemId,bid: datas[0].bid}})
                            .success(function (res) {
                                if (res.code == 0) {
                                    layer.msg('成功！');
                                    setTimeout(function(){
                                        layer.closeAll();
                                        location.reload();
                                    }, 3000);
                                } else {
                                    layer.msg(res.msg);
                                    layer.closeAll();
                                }
                            })
                            .error(function(result){
                                layer.close();
                                layer.msg("操作失败，请稍后再试！", {icon: 2});
                            });

                    }, function() {
                    });
                }
                break;
            }
            case 'event-to-export'://导出
            {
                $scope.doExport('/api/inter/tcgPurchaseContractByManage/export');
                break;
            }

        };
    }
}

//表格双击
app.controller('dbClickCtrl', ['$scope', '$http', DbClickController]);
function DbClickController($scope, $http){
    $scope.doubleClick = function(data) {
        window.top.add_tab('采购合同管理 - 详情','/web/purchase/tcgPurchaseContractByManage/toDetail?itemId=' + data.itemId);
    }
}


